<!doctype html>



  


<html class="theme-next mist use-motion" lang="zh-Hans">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>



<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />



  <meta name="google-site-verification" content="TrUnMASAEpWPLf28sUVl5VSxwgl4myBCO_6PiHidBaU" />













  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />




  
  
  
  

  
    
    
  

  

  

  

  

  
    
    
    <link href="//fonts.lug.ustc.edu.cn//css?family=Lato:300,300italic,400,400italic,700,700italic&subset=latin,latin-ext" rel="stylesheet" type="text/css">
  






  

<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.6.2/css/font-awesome.min.css" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.1.0" rel="stylesheet" type="text/css" />


  <meta name="keywords" content="JAVA,CPU过高," />





  <link rel="alternate" href="/atom.xml" title="Sam's Blog" type="application/atom+xml" />




  <link rel="shortcut icon" type="image/x-icon" href="/favicon.ico?v=5.1.0" />






<meta name="description" content="1.利用TOP命令查看，发现Java进程持续占高CPUPID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND                                   4233 root      20   0 6667m 2.3g 8312 S 264.1 30.4  79979:06 java 2.利用TO">
<meta name="keywords" content="JAVA,CPU过高">
<meta property="og:type" content="article">
<meta property="og:title" content="Java进程占用CPU过高排查方法">
<meta property="og:url" content="http://blog.lisanlai.cn/2016/07/27/Java进程占用CPU过高排查方法/index.html">
<meta property="og:site_name" content="Sam&#39;s Blog">
<meta property="og:description" content="1.利用TOP命令查看，发现Java进程持续占高CPUPID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND                                   4233 root      20   0 6667m 2.3g 8312 S 264.1 30.4  79979:06 java 2.利用TO">
<meta property="og:locale" content="zh-Hans">
<meta property="og:updated_time" content="2018-07-10T02:38:15.609Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="Java进程占用CPU过高排查方法">
<meta name="twitter:description" content="1.利用TOP命令查看，发现Java进程持续占高CPUPID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND                                   4233 root      20   0 6667m 2.3g 8312 S 264.1 30.4  79979:06 java 2.利用TO">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Mist',
    sidebar: {"position":"left","display":"post","offset":12,"offset_float":0,"b2t":false,"scrollpercent":false},
    fancybox: true,
    motion: true,
    duoshuo: {
      userId: '6275635457204159000',
      author: 'Author'
    },
    algolia: {
      applicationID: 'KWML0K50GI',
      apiKey: 'd54291e92bb62d32f0fbc5f0b6732a22',
      indexName: 'Index_blog_lisanlai_cn',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="http://blog.lisanlai.cn/2016/07/27/Java进程占用CPU过高排查方法/"/>





  <title> Java进程占用CPU过高排查方法 | Sam's Blog </title>
</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  














  
  
    
  

  <div class="container sidebar-position-left page-post-detail ">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/"  class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">Sam's Blog</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <h1 class="site-subtitle" itemprop="description"></h1>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br />
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            
            归档
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />
            
            标签
          </a>
        </li>
      

      
        <li class="menu-item menu-item-search">
          
            <a href="javascript:;" class="popup-trigger">
          
            
              <i class="menu-item-icon fa fa-search fa-fw"></i> <br />
            
            搜索
          </a>
        </li>
      
    </ul>
  

  
    <div class="site-search">
      
  
  <div class="algolia-popup popup search-popup">
    <div class="algolia-search">
      <div class="algolia-search-input-icon">
        <i class="fa fa-search"></i>
      </div>
      <div class="algolia-search-input" id="algolia-search-input"></div>
    </div>

    <div class="algolia-results">
      <div id="algolia-stats"></div>
      <div id="algolia-hits"></div>
      <div id="algolia-pagination" class="algolia-pagination"></div>
    </div>

    <span class="popup-btn-close">
      <i class="fa fa-times-circle"></i>
    </span>
  </div>




    </div>
  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal " itemscope itemtype="http://schema.org/Article">
    <link itemprop="mainEntityOfPage" href="http://blog.lisanlai.cn/2016/07/27/Java进程占用CPU过高排查方法/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="李三来">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/avatar.png">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Sam's Blog">
    </span>

    
      <header class="post-header">

        
        
          <h2 class="post-title" itemprop="name headline">
            
            
              
                Java进程占用CPU过高排查方法
              
            
          </h2>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2016-07-27T10:06:05+08:00">
                2016-07-27
              </time>
            

            

            
          </span>

          
            <span class="post-category" >
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/Development/" itemprop="url" rel="index">
                    <span itemprop="name">Development</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
              <span class="post-comments-count">
                <span class="post-meta-divider">|</span>
                <span class="post-meta-item-icon">
                  <i class="fa fa-comment-o"></i>
                </span>
                <a href="/2016/07/27/Java进程占用CPU过高排查方法/#comments" itemprop="discussionUrl">
                  <span class="post-comments-count ds-thread-count" data-thread-key="2016/07/27/Java进程占用CPU过高排查方法/" itemprop="commentCount"></span>
                </a>
              </span>
            
          

          
          

          

          

          

        </div>
      </header>
    


    <div class="post-body" itemprop="articleBody">

      
      

      
        <h2 id="1-利用TOP命令查看，发现Java进程持续占高CPU"><a href="#1-利用TOP命令查看，发现Java进程持续占高CPU" class="headerlink" title="1.利用TOP命令查看，发现Java进程持续占高CPU"></a>1.利用TOP命令查看，发现Java进程持续占高CPU</h2><pre><code>PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND                                  
4233 root      20   0 6667m 2.3g 8312 S 264.1 30.4  79979:06 java
</code></pre><h2 id="2-利用TOP-H找到对应进程下面线程的耗CPU情况"><a href="#2-利用TOP-H找到对应进程下面线程的耗CPU情况" class="headerlink" title="2.利用TOP -H找到对应进程下面线程的耗CPU情况"></a>2.利用TOP -H找到对应进程下面线程的耗CPU情况</h2><pre><code># top -H -p 4233
PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND                                  
 7041 root      20   0 6667m 2.3g 8312 S 20.1 30.4   5524:52 java                                     
 7048 root      20   0 6667m 2.3g 8312 S 18.8 30.4   5098:27 java                                     
 9625 root      20   0 6667m 2.3g 8312 S 18.5 30.4   7205:30 java                                     
10111 root      20   0 6667m 2.3g 8312 S 17.8 30.4   6008:08 java                                     
10254 root      20   0 6667m 2.3g 8312 S 17.8 30.4   6001:12 java                                     
10923 root      20   0 6667m 2.3g 8312 S 17.5 30.4   5999:17 java                                     
10033 root      20   0 6667m 2.3g 8312 S 17.1 30.4   6004:10 java                                     
 4353 root      20   0 6667m 2.3g 8312 S 16.8 30.4   7209:04 java                                     
 9685 root      20   0 6667m 2.3g 8312 S 16.8 30.4   6002:45 java                                     
 7042 root      20   0 6667m 2.3g 8312 S 16.5 30.4   7193:56 java                                     
 9910 root      20   0 6667m 2.3g 8312 S 16.5 30.4   6010:04 java                                     
10893 root      20   0 6667m 2.3g 8312 S 16.5 30.4   7195:46 java                                     
 4235 root      20   0 6667m 2.3g 8312 S 15.5 30.4 815:26.39 java                                          4238 root      20   0 6667m 2.3g 8312 R 12.9 30.4 815:54.11 java                                     
 4236 root      20   0 6667m 2.3g 8312 S 12.5 30.4 811:10.16 java                                     
 4237 root      20   0 6667m 2.3g 8312 S  9.6 30.4 814:50.57 java                                     
 4239 root      20   0 6667m 2.3g 8312 S  2.0 30.4 752:01.99 java                                          4294 root      20   0 6667m 2.3g 8312 S  0.7 30.4  56:16.83 java                                     
 4280 root      20   0 6667m 2.3g 8312 S  0.3 30.4  68:25.58 java                                     
 4233 root      20   0 6667m 2.3g 8312 S  0.0 30.4   0:00.00 java                                     
 4234 root      20   0 6667m 2.3g 8312 S  0.0 30.4   0:07.16 java                                     
 4240 root      20   0 6667m 2.3g 8312 S  0.0 30.4   0:10.14 java                                     
 4241 root      20   0 6667m 2.3g 8312 S  0.0 30.4   0:08.93 java                                     
 4242 root      20   0 6667m 2.3g 8312 S  0.0 30.4   0:00.00 java                                     
 4243 root      20   0 6667m 2.3g 8312 S  0.0 30.4   0:52.14 java                                     
 4244 root      20   0 6667m 2.3g 8312 S  0.0 30.4   0:47.82 java                                          4245 root      20   0 6667m 2.3g 8312 S  0.0 30.4   0:00.00 java                                     
 4246 root      20   0 6667m 2.3g 8312 S  0.0 30.4  19:30.64 java                                     
 4249 root      20   0 6667m 2.3g 8312 S  0.0 30.4   0:03.20 java 
</code></pre><a id="more"></a>     
<h2 id="3-将需要查看的线程ID转换为16进制格式"><a href="#3-将需要查看的线程ID转换为16进制格式" class="headerlink" title="3.将需要查看的线程ID转换为16进制格式"></a>3.将需要查看的线程ID转换为16进制格式</h2><pre><code># printf &quot;%x\n&quot; 7041
1b81
</code></pre><h2 id="4-打印线程的堆栈信息"><a href="#4-打印线程的堆栈信息" class="headerlink" title="4.打印线程的堆栈信息"></a>4.打印线程的堆栈信息</h2><pre><code># jstack 4233|grep 1b81 -A 30 
&quot;http-80-61&quot; daemon prio=10 tid=0x00007f75e8067000 nid=0x1b81 runnable [0x00007f75733f1000]
       java.lang.Thread.State: RUNNABLE
        at com.saas.biz.commen.FilterChar.ignoreCaseIndexOf(FilterChar.java:94)
        at com.saas.biz.commen.FilterChar.repex(FilterChar.java:41)
        at com.saas.sys.dbm.Dbexecute.setQueryParam(Dbexecute.java:627)
        at com.saas.sys.dbm.Dbexecute.selBizQuery(Dbexecute.java:426)
        at com.saas.biz.dao.areaDAO.AreaExt.selByList(AreaExt.java:25)
        at com.saas.biz.AreaInfoMgr.AreaInfo.getAllClassListForAdd(AreaInfo.java:1493)
        at org.apache.jsp.car.supplier_jsp._jspService(supplier_jsp.java:116)
        at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:723)
        at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:388)
        at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
        at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:723)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:646)
        at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:436)
        at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:374)
        at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:302)
        at org.tuckey.web.filters.urlrewrite.NormalRewrittenUrl.doRewrite(NormalRewrittenUrl.java:195)
        at org.tuckey.web.filters.urlrewrite.RuleChain.handleRewrite(RuleChain.java:159)
        at org.tuckey.web.filters.urlrewrite.RuleChain.doRules(RuleChain.java:141)
        at org.tuckey.web.filters.urlrewrite.UrlRewriter.processRequest(UrlRewriter.java:90)
        at org.tuckey.web.filters.urlrewrite.UrlRewriteFilter.doFilter(UrlRewriteFilter.java:417)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
        at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:470)
</code></pre><h2 id="5-在堆栈信息里面找到你熟悉的字眼，去排查相关问题。"><a href="#5-在堆栈信息里面找到你熟悉的字眼，去排查相关问题。" class="headerlink" title="5.在堆栈信息里面找到你熟悉的字眼，去排查相关问题。"></a>5.在堆栈信息里面找到你熟悉的字眼，去排查相关问题。</h2>
      
    </div>

    <div>
      
        

      
    </div>

    <div>
      
        

      
    </div>

    <div>
      
        

      
    </div>

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/JAVA/" rel="tag"># JAVA</a>
          
            <a href="/tags/CPU过高/" rel="tag"># CPU过高</a>
          
        </div>
      

      
        
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2016/04/29/文件提取利器-Apache-Tika/" rel="next" title="文件提取利器-Apache Tika">
                <i class="fa fa-chevron-left"></i> 文件提取利器-Apache Tika
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2016/11/23/从源码编译安装nginx/" rel="prev" title="从源码编译安装nginx">
                从源码编译安装nginx <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          

  <p>热评文章</p>
  <div class="ds-top-threads" data-range="weekly" data-num-items="4"></div>


          
  <div class="comments" id="comments">
    
      <div class="ds-thread" data-thread-key="2016/07/27/Java进程占用CPU过高排查方法/"
           data-title="Java进程占用CPU过高排查方法" data-url="http://blog.lisanlai.cn/2016/07/27/Java进程占用CPU过高排查方法/">
      </div>
    
  </div>


        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap" >
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
          <img class="site-author-image" itemprop="image"
               src="/images/avatar.png"
               alt="李三来" />
          <p class="site-author-name" itemprop="name">李三来</p>
           
              <p class="site-description motion-element" itemprop="description"></p>
           
        </div>
        <nav class="site-state motion-element">

          
            <div class="site-state-item site-state-posts">
              <a href="/archives">
                <span class="site-state-item-count">14</span>
                <span class="site-state-item-name">日志</span>
              </a>
            </div>
          

          
            
            
            <div class="site-state-item site-state-categories">
              <a href="/categories/index.html">
                <span class="site-state-item-count">4</span>
                <span class="site-state-item-name">分类</span>
              </a>
            </div>
          

          
            
            
            <div class="site-state-item site-state-tags">
              <a href="/tags/index.html">
                <span class="site-state-item-count">20</span>
                <span class="site-state-item-name">标签</span>
              </a>
            </div>
          

        </nav>

        
          <div class="feed-link motion-element">
            <a href="/atom.xml" rel="alternate">
              <i class="fa fa-rss"></i>
              RSS
            </a>
          </div>
        

        <div class="links-of-author motion-element">
          
            
              <span class="links-of-author-item">
                <a href="https://github.com/lisanlai" target="_blank" title="GitHub">
                  
                    <i class="fa fa-fw fa-github"></i>
                  
                  GitHub
                </a>
              </span>
            
              <span class="links-of-author-item">
                <a href="https://twitter.com/SanlaiLi" target="_blank" title="Twitter">
                  
                    <i class="fa fa-fw fa-twitter"></i>
                  
                  Twitter
                </a>
              </span>
            
          
        </div>

        
        

        
        
          <div class="links-of-blogroll motion-element links-of-blogroll-block">
            <div class="links-of-blogroll-title">
              <i class="fa  fa-fw fa-globe"></i>
              Links
            </div>
            <ul class="links-of-blogroll-list">
              
                <li class="links-of-blogroll-item">
                  <a href="http://zoom.us" title="zoom" target="_blank">zoom</a>
                </li>
              
            </ul>
          </div>
        

        


      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#1-利用TOP命令查看，发现Java进程持续占高CPU"><span class="nav-number">1.</span> <span class="nav-text">1.利用TOP命令查看，发现Java进程持续占高CPU</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#2-利用TOP-H找到对应进程下面线程的耗CPU情况"><span class="nav-number">2.</span> <span class="nav-text">2.利用TOP -H找到对应进程下面线程的耗CPU情况</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#3-将需要查看的线程ID转换为16进制格式"><span class="nav-number">3.</span> <span class="nav-text">3.将需要查看的线程ID转换为16进制格式</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#4-打印线程的堆栈信息"><span class="nav-number">4.</span> <span class="nav-text">4.打印线程的堆栈信息</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#5-在堆栈信息里面找到你熟悉的字眼，去排查相关问题。"><span class="nav-number">5.</span> <span class="nav-text">5.在堆栈信息里面找到你熟悉的字眼，去排查相关问题。</span></a></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright" >
  
  &copy; 
  <span itemprop="copyrightYear">2018</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">李三来</span>
</div>


<div class="powered-by">
  由 <a class="theme-link" href="https://hexo.io">Hexo</a> 强力驱动
</div>

<div class="theme-info">
  主题 -
  <a class="theme-link" href="https://github.com/iissnan/hexo-theme-next">
    NexT.Mist
  </a>
</div>


        

        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  






  
  <script type="text/javascript" src="https://cdn.bootcss.com/jquery/2.1.3/jquery.min.js"></script>

  
  <script type="text/javascript" src="https://cdn.bootcss.com/fastclick/1.0.6/fastclick.min.js"></script>

  
  <script type="text/javascript" src="https://cdn.bootcss.com/jquery_lazyload/1.9.7/jquery.lazyload.min.js"></script>

  
  <script type="text/javascript" src="https://cdn.bootcss.com/velocity/1.2.1/velocity.min.js"></script>

  
  <script type="text/javascript" src="https://cdn.bootcss.com/velocity/1.2.1/velocity.ui.min.js"></script>

  
  <script type="text/javascript" src="https://cdn.bootcss.com/fancybox/2.1.5/jquery.fancybox.pack.js"></script>


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.0"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.0"></script>



  
  

  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.0"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.0"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.0"></script>



  

  
    
  

  <script type="text/javascript">
    var duoshuoQuery = {short_name:"lisanlai"};
    (function() {
      var ds = document.createElement('script');
      ds.type = 'text/javascript';ds.async = true;
      ds.id = 'duoshuo-script';
      ds.src = (document.location.protocol == 'https:' ? 'https:' : 'http:') + '//static.duoshuo.com/embed.js';
      ds.charset = 'UTF-8';
      (document.getElementsByTagName('head')[0]
      || document.getElementsByTagName('body')[0]).appendChild(ds);
    })();
  </script>

  
    
      
      <script src="https://cdn.bootcss.com/UAParser.js/0.7.9/ua-parser.min.js"></script>
      <script src="/js/src/hook-duoshuo.js?v=5.1.0"></script>
    
    
    <script src="https://cdn.bootcss.com/UAParser.js/0.7.9/ua-parser.min.js"></script>
    <script src="/js/src/hook-duoshuo.js"></script>
  
















  

  <script type="text/javascript">
    // Popup Window;
    var isfetched = false;
    // Search DB path;
    var search_path = "search.xml";
    if (search_path.length == 0) {
      search_path = "search.xml";
    }
    var path = "/" + search_path;
    // monitor main search box;

    function proceedsearch() {
      $("body")
        .append('<div class="search-popup-overlay local-search-pop-overlay"></div>')
        .css('overflow', 'hidden');
      $('.popup').toggle();
    }
    // search function;
    var searchFunc = function(path, search_id, content_id) {
      'use strict';
      $.ajax({
        url: path,
        dataType: "xml",
        async: true,
        success: function( xmlResponse ) {
          // get the contents from search data
          isfetched = true;
          $('.popup').detach().appendTo('.header-inner');
          var datas = $( "entry", xmlResponse ).map(function() {
            return {
              title: $( "title", this ).text(),
              content: $("content",this).text(),
              url: $( "url" , this).text()
            };
          }).get();
          var $input = document.getElementById(search_id);
          var $resultContent = document.getElementById(content_id);
          $input.addEventListener('input', function(){
            var matchcounts = 0;
            var str='<ul class=\"search-result-list\">';
            var keywords = this.value.trim().toLowerCase().split(/[\s\-]+/);
            $resultContent.innerHTML = "";
            if (this.value.trim().length > 1) {
              // perform local searching
              datas.forEach(function(data) {
                var isMatch = false;
                var content_index = [];
                var data_title = data.title.trim().toLowerCase();
                var data_content = data.content.trim().replace(/<[^>]+>/g,"").toLowerCase();
                var data_url = decodeURIComponent(data.url);
                var index_title = -1;
                var index_content = -1;
                var first_occur = -1;
                // only match artiles with not empty titles and contents
                if(data_title != '') {
                  keywords.forEach(function(keyword, i) {
                    index_title = data_title.indexOf(keyword);
                    index_content = data_content.indexOf(keyword);
                    if( index_title >= 0 || index_content >= 0 ){
                      isMatch = true;
                      if (i == 0) {
                        first_occur = index_content;
                      }
                    }

                  });
                }
                // show search results
                if (isMatch) {
                  matchcounts += 1;
                  str += "<li><a href='"+ data_url +"' class='search-result-title'>"+ data_title +"</a>";
                  var content = data.content.trim().replace(/<[^>]+>/g,"");
                  if (first_occur >= 0) {
                    // cut out 100 characters
                    var start = first_occur - 20;
                    var end = first_occur + 80;
                    if(start < 0){
                      start = 0;
                    }
                    if(start == 0){
                      end = 50;
                    }
                    if(end > content.length){
                      end = content.length;
                    }
                    var match_content = content.substring(start, end);
                    // highlight all keywords
                    keywords.forEach(function(keyword){
                      var regS = new RegExp(keyword, "gi");
                      match_content = match_content.replace(regS, "<b class=\"search-keyword\">"+keyword+"</b>");
                    });

                    str += "<p class=\"search-result\">" + match_content +"...</p>"
                  }
                  str += "</li>";
                }
              })};
            str += "</ul>";
            if (matchcounts == 0) { str = '<div id="no-result"><i class="fa fa-frown-o fa-5x" /></div>' }
            if (keywords == "") { str = '<div id="no-result"><i class="fa fa-search fa-5x" /></div>' }
            $resultContent.innerHTML = str;
          });
          proceedsearch();
        }
      });}

    // handle and trigger popup window;
    $('.popup-trigger').click(function(e) {
      e.stopPropagation();
      if (isfetched == false) {
        searchFunc(path, 'local-search-input', 'local-search-result');
      } else {
        proceedsearch();
      };
    });

    $('.popup-btn-close').click(function(e){
      $('.popup').hide();
      $(".local-search-pop-overlay").remove();
      $('body').css('overflow', '');
    });
    $('.popup').click(function(e){
      e.stopPropagation();
    });
  </script>




  
  
  
  <link rel="stylesheet" href="/lib/algolia-instant-search/instantsearch.min.css">

  
  
  <script src="/lib/algolia-instant-search/instantsearch.min.js"></script>
  

  <script src="/js/src/algolia-search.js?v=5.1.0"></script>



  

  
<script>
(function(){
    var bp = document.createElement('script');
    var curProtocol = window.location.protocol.split(':')[0];
    if (curProtocol === 'https') {
        bp.src = 'https://zz.bdstatic.com/linksubmit/push.js';        
    }
    else {
        bp.src = 'http://push.zhanzhang.baidu.com/push.js';
    }
    var s = document.getElementsByTagName("script")[0];
    s.parentNode.insertBefore(bp, s);
})();
</script>


  

  

</body>
</html>
